/**
 * 
 */
package com.kathez.dao;

import java.util.List;

import com.kathez.entity.BusinessOperable;
import com.kathez.entity.KathezEntity;
import com.kathez.exceptions.KathezRuntimeException;

/**
 * @author Balaji T
 *
 */
public final class DAOUpdateResultImpl extends AbstractDAOUpdateResult {

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAOUpdateResult#getUpdateCount()
	 */
	@Override
	public int getUpdateCount() {
		return this.updateCount;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAOUpdateResult#getUpdateErrCode()
	 */
	@Override
	public String getUpdateErrCode() {
		return this.updateErrCode;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAOUpdateResult#getUpdateErrMsg()
	 */
	@Override
	public String getUpdateErrMsg() {
		return this.updateErrMsg;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAOUpdateResult#getUpdatedObject()
	 */
	@Override
	public BusinessOperable getUpdatedObject() {
		return this.updatedObject;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAOUpdateResult#getUpdatedObjectList()
	 */
	@Override
	public List<KathezEntity> getUpdatedObjectList() {
		return this.updatedObjectList;
	}

	/* (non-Javadoc)
	 * @see com.kathez.dao.DAOUpdateResult#isUpdateSuccess()
	 */
	@Override
	public boolean isUpdateSuccess() {
		return this.updateSuccess;
	}
	
	private int updateCount;
	private String updateErrCode;
	private String updateErrMsg;
	private BusinessOperable updatedObject;
	private List<KathezEntity> updatedObjectList;
	private boolean updateSuccess;
	private boolean overrideSuccesFlag;
	/**
	 * @param updateCount the updateCount to set
	 */
	private void setUpdateCount(int updateCount) {
		this.updateCount = updateCount;
	}

	/**
	 * @param updateErrCode the updateErrCode to set
	 */
	public void setUpdateErrCode(String updateErrCode) {
		this.updateErrCode = updateErrCode;
	}

	/**
	 * @param updateErrMsg the updateErrMsg to set
	 */
	public void setUpdateErrMsg(String updateErrMsg) {
		this.updateErrMsg = updateErrMsg;
	}

	/**
	 * @param updatedObject the updatedObject to set
	 */
	public void setUpdatedObject(BusinessOperable updatedObject) {
		if(updatedObject != null){
			if(this.updatedObjectList != null)
				throw new KathezRuntimeException("The Result already set for this object. The existing result is List of Updated objects");
			this.updatedObject = updatedObject;
			setUpdateCount(1);
			if(overrideSuccesFlag && !this.updateSuccess)
				this.updateSuccess = false;
			else
				this.updateSuccess = true;
		}
		this.overrideSuccesFlag = false;
	}

	/**
	 * @param updatedObjectList the updatedObjectList to set
	 */
	public void setUpdatedObjectList(List<KathezEntity> updatedObjectList) {
		if(updatedObjectList != null){
			if(this.updatedObject != null)
				throw new KathezRuntimeException("The Result already set for this object. The existing result is Single Updated object");
			this.updatedObjectList = updatedObjectList;
			setUpdateCount(updatedObjectList.size());
			if(overrideSuccesFlag && !this.updateSuccess)
				this.updateSuccess = false;
			else
				this.updateSuccess = true;
		}
		this.overrideSuccesFlag = false;
	}

	/**
	 * @param updateSuccess the updateSuccess to set
	 */
	public void setUpdateSuccess(boolean updateSuccess) {
		this.overrideSuccesFlag = true;
		this.updateSuccess = updateSuccess;
	}
}
